package com.example.smartmedicalsystem.controller;

import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class LoginSuccessController {

    @GetMapping("/redirect")
    public String redirectAfterLogin(Authentication authentication) {
        // 判断当前用户的角色，根据角色返回相应的重定向 URL
        if (authentication.getAuthorities().stream().anyMatch(auth -> auth.getAuthority().equals("ROLE_ADMIN"))) {
            return "redirect:/admin.html";
        } else if (authentication.getAuthorities().stream().anyMatch(auth -> auth.getAuthority().equals("ROLE_DOCTOR"))) {
            return "redirect:/doctor.html";
        } else if (authentication.getAuthorities().stream().anyMatch(auth -> auth.getAuthority().equals("ROLE_PATIENT"))) {
            return "redirect:/patient.html";
        }
        // 默认重定向到首页
        return "redirect:/index.html";
    }
}